﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bounce : MonoBehaviour {
    public Collider2D cd;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
      
	}

    private void OnCollisionEnter2D(Collision2D collision)
    {
        //print(collision.rigidbody);
        Rigidbody2D rig = collision.rigidbody;
        Vector2 radial = (Vector2)rig.position - (Vector2)this.transform.position;//两个碰撞体中心点连线
       // print(radial);
        radial = radial.normalized;//单位向量
        print(radial);
        print(rig.velocity);
        print("chengfa");
        print(Vector2.Dot(rig.velocity, radial));
        radial = Mathf.Abs(Vector2.Dot(rig.transform.up, radial)) * 10 * radial;

        print(radial);
        rig.velocity += radial;
    }
}
